//
//  NSString+SNExtension.m
//  Truck
//
//  Created by 田安忠 on 16/3/24.
//  Copyright © 2016年 樊皓天. All rights reserved.
//

#import "NSString+SNExtension.h"

@implementation NSString (SNExtension)

/** 根据字体获取字符串的尺寸 */
- (CGSize)sizeWithFont:(UIFont *)font
{
    return [self sizeWithFont:font maxW:MAXFLOAT];
}

/** 根据字体和宽度获取字符串的尺寸 */
- (CGSize)sizeWithFont:(UIFont *)font maxW:(CGFloat)maxW
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = font;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    
    return [self boundingRectWithSize:maxSize
                              options:NSStringDrawingUsesLineFragmentOrigin
                           attributes:attrs
                              context:nil].size;
}



@end
